<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>mindsensors-ps2ctrl-v4-test2.c</h1>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="preprocessor">#pragma config(Sensor, S1,     PSPNXV4,        sensorI2CCustom)</span>
<span class="preprocessor"></span><span class="preprocessor">#pragma config(Motor,  motorA,          ARMS,          tmotorNormal, PIDControl, encoder)</span>
<span class="preprocessor"></span><span class="preprocessor">#pragma config(Motor,  motorB,          RIGHT,         tmotorNormal, PIDControl, encoder)</span>
<span class="preprocessor"></span><span class="preprocessor">#pragma config(Motor,  motorC,          LEFT,          tmotorNormal, PIDControl, encoder)</span>
<span class="preprocessor"></span><span class="comment">//*!!Code automatically generated by &#39;ROBOTC&#39; configuration wizard               !!*//</span>

<span class="comment">/*</span>
<span class="comment"> * $Id: mindsensors-ps2ctrl-v4-test2.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
<span class="comment"></span>
<span class="comment">/**</span>
<span class="comment"> * mindsensors-ps2ctrl-v4.h provides an API for the Mindsensors PS2 controller sensor</span>
<span class="comment"> * with referee signal receiver.  This program demonstrates how to use that API</span>
<span class="comment"> *</span>
<span class="comment"> * Changelog:</span>
<span class="comment"> * - 0.1: Initial release</span>
<span class="comment"> *</span>
<span class="comment"> * Credits:</span>
<span class="comment"> * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.</span>
<span class="comment"> *</span>
<span class="comment"> * License: You may use this code as you wish, provided you give credit where it&#39;s due.</span>
<span class="comment"> *</span>
<span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<span class="comment"></span>
<span class="comment"> * Xander Soldaat (xander_at_botbench.com)</span>
<span class="comment"> * 02 August 2012</span>
<span class="comment"> * version 0.1</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &quot;<a class="code" href="mindsensors-ps2ctrl-v4_8h.html" title="Playstation 2 Controller Sensor.">drivers/mindsensors-ps2ctrl-v4.h</a>&quot;</span>

task main ()
{
  ubyte counter = 0;
  ubyte oldCounter = 0;
  ubyte refSignal = 0;
  ubyte oldRefSignal = 0;
  ubyte txType = 0;
  <span class="keywordtype">long</span> rawValue = 0;

  nxtDisplayCenteredTextLine(0, <span class="stringliteral">&quot;Mindsensors&quot;</span>);
  nxtDisplayCenteredBigTextLine(1, <span class="stringliteral">&quot;PSP-Nx&quot;</span>);
  nxtDisplayCenteredTextLine(3, <span class="stringliteral">&quot;Test 2&quot;</span>);
  wait1Msec(2000);

  PlaySound(soundBeepBeep);
  <span class="keywordflow">while</span>(bSoundActive) EndTimeSlice();

  eraseDisplay();
  <span class="keywordflow">while</span> (<span class="keyword">true</span>)
  {
    <span class="comment">// Get the current counter value, wraps at 255</span>
    counter = <a name="a0"></a><a class="code" href="group___p_s_p4.html#ga8ef579448f32b14702039578d25d0829">PSPV4readRefSignalCount</a>(PSPNXV4);

    <span class="keywordflow">if</span> (oldCounter != counter)
    {
      <span class="comment">// This is the command sent by the remote control, can be:</span>
      <span class="comment">// PSPV4_SIGNAL_FAST_REWIND</span>
      <span class="comment">// PSPV4_SIGNAL_FAST_FORWARD</span>
      <span class="comment">// PSPV4_SIGNAL_PLAY</span>
      <span class="comment">// PSPV4_SIGNAL_STOP</span>
      refSignal =  <a name="a1"></a><a class="code" href="group___p_s_p4.html#ga05068a35c691b19daae9ddbcd098da84">PSPV4readRefSignal</a>(PSPNXV4);

      <span class="comment">// Get the transmitted type.  Not very useful in most cases unless</span>
      <span class="comment">// you need to know what type of transmitter sent the command</span>
                        txType = <a name="a2"></a><a class="code" href="group___p_s_p4.html#gaddc1f44924b7c24e39e0e88485636ba3">PSPV4readRefTXType</a>(PSPNXV4);

                        <span class="comment">// Raw value will also &quot;see&quot; commands from the remote</span>
                        <span class="comment">// that are not recognised as &quot;play&quot;, &quot;stop&quot;, &quot;forward&quot; or &quot;rewind&quot;.</span>
                        <span class="comment">// You could use this to control additional aspects of your robot!</span>
                        rawValue = <a name="a3"></a><a class="code" href="group___p_s_p4.html#ga808007b50ad236e78649a42d0c3b41ee">PSPV4readRawRefTXValue</a>(PSPNXV4);

      <span class="keywordflow">if</span> (oldRefSignal != refSignal)
      {
              PlaySound(soundShortBlip);
                    <span class="keywordflow">switch</span>(refSignal)
                    {
                      <span class="keywordflow">case</span> <a name="a4"></a><a class="code" href="group___p_s_p4.html#ga1c9bdc5f4a8306db3b4f080d2863806e">PSPV4_SIGNAL_FAST_REWIND</a>:   nxtDisplayCenteredBigTextLine(3,<span class="stringliteral">&quot;REWIND&quot;</span>); <span class="keywordflow">break</span>;
                      <span class="keywordflow">case</span> <a name="a5"></a><a class="code" href="group___p_s_p4.html#ga703a7ff57c6f2af1a0269a691f0da8fb">PSPV4_SIGNAL_FAST_FORWARD</a>:  nxtDisplayCenteredBigTextLine(3,<span class="stringliteral">&quot;FORWARD&quot;</span>); <span class="keywordflow">break</span>;
                      <span class="keywordflow">case</span> <a name="a6"></a><a class="code" href="group___p_s_p4.html#ga6b8c8bdf21d6e9e7c3c15397ecd49ac5">PSPV4_SIGNAL_PLAY</a>:          nxtDisplayCenteredBigTextLine(3,<span class="stringliteral">&quot;PLAY&quot;</span>); <span class="keywordflow">break</span>;
                      <span class="keywordflow">case</span> <a name="a7"></a><a class="code" href="group___p_s_p4.html#ga997ac1dfec9ccdd72f89b6f802232c04">PSPV4_SIGNAL_STOP</a>:          nxtDisplayCenteredBigTextLine(3,<span class="stringliteral">&quot;STOP&quot;</span>); <span class="keywordflow">break</span>;
                    }
                  }

                  <span class="comment">// Always display the raw value, even if it&#39;s not one of the four</span>
                  <span class="comment">// referee signals.  Handy if you want to add more commands to your robot!</span>
            nxtDisplayTextLine(6, <span class="stringliteral">&quot;Type:  0x%02X&quot;</span>, txType);
            nxtDisplayTextLine(7, <span class="stringliteral">&quot;Raw:  0x%03X&quot;</span>, rawValue);

            <span class="comment">// Update the counters and signals</span>
            oldCounter = counter;
            oldRefSignal = refSignal;
          }
    wait1Msec(50);
  }
}


<span class="comment">/*</span>
<span class="comment"> * $Id: mindsensors-ps2ctrl-v4-test2.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
</pre></div> </div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:42 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
